package com.dlmz.view;

import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.dlmz.model.Medicalchart;
import com.dlmz.util.BaseDao;
import com.dlmz.util.ResultSetToMedical;

@SuppressWarnings("serial")
public class MedicalModel extends AbstractTableModel{

	@SuppressWarnings("rawtypes")
	private Vector columnNames;  
    @SuppressWarnings("rawtypes")
	private Vector rowDates;  
    //========查询病历 
    @SuppressWarnings({ "unchecked", "rawtypes" })
	public void queryMedical(String sql,Object...objects)  
    {  
        BaseDao baseDao = null;  
        //========初始化JTable信息  
        columnNames = new Vector();  
        rowDates = new Vector();  
        columnNames.add("病历单号"); columnNames.add("学号");
        columnNames.add("学生姓名");  
        columnNames.add("医生"); columnNames.add("病历日期");  
        columnNames.add("诊断结果"); columnNames.add("治疗意见");  
        
        try {  
            baseDao = new BaseDao();  
            
            List list= baseDao.query(sql, new ResultSetToMedical(),objects);  
            if (list.size()>0) {
            	for (int i = 0; i < list.size(); i++) {
    				Medicalchart medicalchart=(Medicalchart) list.get(i);
    				//System.out.println(student.toString());
    				Vector row = new Vector(); 
                    row.add(medicalchart.getMnum());  
                    row.add(medicalchart.getSno());  
                    row.add(medicalchart.getSname());  
                    row.add(medicalchart.getDname());  
                    row.add(medicalchart.getMdate());  
                    row.add(medicalchart.getDiagnosis()); 
                    row.add(medicalchart.getMrecord());
                    rowDates.add(row);
    			}
    		}	 
        } catch (Exception e) {  
            // TODO: handle exception  
        }   
    }  
  
    public int getColumnCount() {  
  //告知列数，用标题数组的大小,这样表格就是rowData.size()行，columnNames.size()列了  
        return this.columnNames.size();  
    }  
  
    public int getRowCount() {   
        return this.rowDates.size(); 
        //这里是告知表格应该有多少行，我们返回rowDatas上的String数组个数
    }  
  
    @SuppressWarnings("rawtypes")
	public Object getValueAt(int row, int col) {  
        // TODO Auto-generated method stub  
        if(!rowDates.isEmpty())  
            return ((Vector)this.rowDates.get(row)).get(col);  
        else  
            return null;  
    }  
     
    @Override  
    public String getColumnName(int column) {  
        return (String)this.columnNames.get(column);  
      //这里是告知表格各列的列名，我们返回该列的列名
    }    

}
